package com.realbrand.net.realbrandpay.ui.activity.wallet.personer.adress;

import com.realbrand.net.realbrandpay.base.BasePersenter;
import com.realbrand.net.realbrandpay.inter.IAddAddressInfo;

/**
 * Created by Administrator on 2018/5/14.
 */

public class PersenterAddAdress extends BasePersenter<IViewAddAdress> {
    /**
     * 添加地址
     *
     * @param params
     */
    public void addAdress(String params) {
        if (!isViewAttched()) {
            return;
        }
        ModelManagerAdress.addAdress(params, new IModelManagerAdress<String>() {
            @Override
            public void onSuccess(String data) {
                if (isViewAttched()) {
                    getView().showResult(data);
                }
            }

            @Override
            public void onFail(String msg) {
                if (isViewAttched()) {
                    getView().showFailMsg(msg);
                }
            }

            @Override
            public void onErrorr() {
                if (isViewAttched()) {
                    getView().showError();
                }
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 删除地址
     * @param params
     */
    public void deleteAdress(String params) {
        if (!isViewAttched()) {
            return;
        }
        ModelManagerAdress.deleteAdress(params, new IModelManagerAdress<String>() {
            @Override
            public void onSuccess(String data) {
                if (isViewAttched()) {
                    getView().showResult(data);
                }
            }

            @Override
            public void onFail(String msg) {
                if (isViewAttched()) {
                    getView().showFailMsg(msg);
                }
            }

            @Override
            public void onErrorr() {
                if (isViewAttched()) {
                    getView().showError();
                }
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 设置默认地址
     * @param params
     */
    public void setDefaultAdress(String params) {
        if (!isViewAttched()) {
            return;
        }
        ModelManagerAdress.setDefaultAddress(params, new IModelManagerAdress<String>() {
            @Override
            public void onSuccess(String data) {
                if (isViewAttched()) {
                    getView().showResult(data);
                }
            }

            @Override
            public void onFail(String msg) {
                if (isViewAttched()) {
                    getView().showFailMsg(msg);
                }
            }

            @Override
            public void onErrorr() {
                if (isViewAttched()) {
                    getView().showError();
                }
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 更新地址
     * @param params
     */
    public void updataAddress(String params) {
        if (!isViewAttched()) {
            return;
        }
        ModelManagerAdress.upDataAddress(params, new IModelManagerAdress<String>() {
            @Override
            public void onSuccess(String data) {
                if (isViewAttched()) {
                    getView().showResult(data);
                }
            }

            @Override
            public void onFail(String msg) {
                if (isViewAttched()) {
                    getView().showFailMsg(msg);
                }
            }

            @Override
            public void onErrorr() {
                if (isViewAttched()) {
                    getView().showError();
                }
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
